//
//  AppLicationInfo.swift
//  Swift_MyLive
//
//  Created by admin on 16/9/8.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class AppLicationInfo: UIViewController {
    
//MARK: - 创建单利
    class var shareInstance:AppLicationInfo{
        
        struct Singleon{
            static let instance = AppLicationInfo()
        }
        return Singleon.instance
    }
    
    /**
     GET 网络请求
     
     - parameter getUrl:  网址
     - parameter parame:  参数
     - parameter isHead:  头部
     - parameter success: 成功回调
     - parameter failure: 失败回调
     */
    func GET(getUrl:String, parame:NSDictionary?, isHead:Bool, success:@escaping (_ data:NSDictionary) -> Void,failure:@escaping ( _ data:URLSessionDataTask?, _ error:NSError) -> Void)
    {
        let marger = AFHTTPSessionManager()
        
        if isHead {
            marger.requestSerializer.setValue("", forHTTPHeaderField: "")
            
        }
        
        marger.get(getUrl, parameters: parame, progress: { (pro:Progress) in
            
            
            }, success: { (data:URLSessionDataTask, obj:Any?) in
            
                let dic = obj as! NSDictionary
                
                success(dic)
                
            }) { (data:URLSessionDataTask?, error:Error) in
                
                failure(data, error as NSError)
                print(error)
        }
   
    }
    /**
     POST 网络请求
     
     - parameter getUrl:  请求地址
     - parameter parame:  参数
     - parameter isHead:  是否头部
     - parameter success: 成功回调
     - parameter failure: 失败回调
     */
    func POST(getUrl:String, parame:NSDictionary?, isHead:Bool,success:@escaping (_ data:NSDictionary) -> Void,failure:@escaping (_ data:URLSessionDataTask?, _ error:NSError) -> Void)
    {
        let manger = AFHTTPSessionManager()
        manger.responseSerializer.acceptableContentTypes = NSSet.init(objects: "application/json","text/json","text/plain","text/html") as? Set<String>
        
        manger.post(getUrl, parameters: parame, progress: { (pro:Progress) in
            
            }, success: { (data:URLSessionDataTask, obj:Any?) in
                
                let dic = obj as! NSDictionary   
                success(dic)
                
        }) { (data:URLSessionDataTask?, error:Error) in
            
            failure(data, error as NSError)
            
        }
        
    }

}
